package com.pic.mgt.monitor.parser.haishin;

import com.pic.mgt.monitor.WrongUnitFormatException;
import com.pic.mgt.monitor.parser.FormatParser;

public final class HaishinMessageTypeParser extends FormatParser {
	private int transactionFilenameLen;

	@Override
	public String parse(Object _confirmationFilename)
							throws WrongUnitFormatException {
		// 確認是否為 String 型態
		// throws WrongUnitFormatException
		super.checkObjectType(_confirmationFilename, String.class);
		
		String confirmationFilename = (String)_confirmationFilename;
		
		String messageType;
		try {
			messageType = confirmationFilename.substring(this.transactionFilenameLen);
		} catch (IndexOutOfBoundsException e) {
			throw new WrongUnitFormatException(
					"Confirmation filename '" + confirmationFilename + "' format is invalid.", e);
		}
		
		return messageType;
	}

	// --- getter and setter ---
	
	public void setTransactionFilenameLen(int transactionFilenameLen) {
		this.transactionFilenameLen = transactionFilenameLen;
	}

}
